using System;

namespace System.Web.Core
{
    public class OrderField
    {
        private string fieldName = string.Empty;
        private bool isAscending = true;

        public string FieldName
        {
            get
            {
                return fieldName;
            }
            set
            {
                fieldName = value;
            }
        }
        public bool IsAscending
        {
            get
            {
                return isAscending;
            }
            set
            {
                isAscending = value;
            }
        }

        public OrderField()
        {

        }
        public OrderField(string fieldName, bool isAscending)
        {
            this.fieldName = fieldName;
            this.isAscending = isAscending;
            if (string.IsNullOrEmpty(this.fieldName))
            {
                throw new Exception(string.Format("The order field name '{0}' can not be null.", fieldName));
            }
        }
        public OrderField(Entity entity, string propertyName, bool isAscending)
        {
            this.fieldName = entity.GetDBFieldName(propertyName);
            this.isAscending = isAscending;
            if (string.IsNullOrEmpty(this.fieldName))
            {
                throw new Exception(string.Format("Property: {0} does not exist in {1} class.", propertyName, entity.GetType().FullName));
            }
        }
    }
}